# -*- coding: utf-8 -*-
"""
Created on Sun Sep 20 16:52:04 2020

@author: Administrator
"""

'''
Given an m x n matrix. If an element is 0, set its entire row and column to 0. Do it in-place.

Follow up:

A straight forward solution using O(mn) space is probably a bad idea.
A simple improvement uses O(m + n) space, but still not the best solution.
Could you devise a constant space solution?
 

Example 1:


Input: matrix = [[1,1,1],[1,0,1],[1,1,1]]
Output: [[1,0,1],[0,0,0],[1,0,1]]
Example 2:


Input: matrix = [[0,1,2,0],[3,4,5,2],[1,3,1,5]]
Output: [[0,0,0,0],[0,4,5,0],[0,3,1,0]]
 

'''

class Solution:
    def setZeroes(self, matrix: List[List[int]]) -> None:
        """
        Do not return anything, modify matrix in-place instead.
        """
        
        '''
        20200920--李运辰
        '''
        
        m,n =len(matrix),len(matrix[0])
        rows = []
        cols = []
        for x in range(m):
            for y in range(n):
                if matrix[x][y]==0:
                    rows.append(x)
                    cols.append(y)
        for row in rows:
            self.null_rows(matrix,row)
        
        for col in cols:
            self.null_cols(matrix,col)
    
    def null_rows(self,matrix,row):
        for i in range(len(matrix[0])):
                matrix[row][i]=0
    
    def null_cols(self,matrix,col):
        for i in range(len(matrix)):
                matrix[i][col] =0
    
            
                    
                      
        